'use strict';

const parameter_validate = require('./utils/parameter_validate');

module.exports = app => {

  app.once('server', () => {
    // websocket
  });
  app.on('error', (err) => {
    console.log('app - err = ', err);
    // report error
  });
  app.on('request', err => {
    // log receive request
    console.log('app request = ', err.req.url);
  });
  app.on('response', () => {
    // ctx.starttime is set by framework
    // log total cost
  });
  // socket.io
  app.beforeStart(async () => {
    const homeKey = 'CHAT_GROUP_PREFIX:WEB';
    const room = await app.redis.get(homeKey);
    if (!room) {
      await app.redis.set(homeKey, 'WEB');
    }
  });
  /**
   * 自定义参数校验
   */
  parameter_validate(app);
};
